﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;

namespace WindowsFormsApp生产订单开工
{
    public static class SqlSugarHelp
    {

        public static SqlSugarScope scope = new SqlSugarScope(new List<ConnectionConfig> {
            new ConnectionConfig()
        {
            ConnectionString = "server=192.168.10.111;Database=plc;Uid=root;Pwd=Admin@123;AllowLoadLocalInfile=true;Convert Zero Datetime=True;CharSet=utf8mb4;",//连接符字串
            ConfigId = "MySql",
            DbType = DbType.MySql,//数据库类型
            IsAutoCloseConnection = true //不设成true要手动close
        }, new ConnectionConfig()
        {
            ConnectionString = "Data Source=192.168.5.161/ncdb;User Id=flplt;Password=plt202306; enlist=false ;",//连接符字串
            ConfigId = "Oracle",
            DbType = DbType.Oracle,//数据库类型
            IsAutoCloseConnection = true //不设成true要手动close
        }
        },
           db =>
           {
               db.Aop.OnLogExecuting = (sql, pars) =>
        {
            
        };
               db.Aop.OnError = (exp) =>//SQL报错
           {
           };
               db.Aop.OnLogExecuted = (sql, p) =>
               {
                   //执行时间超过1秒
                   if (db.Ado.SqlExecutionTime.TotalSeconds > 1)
                   {
                       //代码CS文件名
                       var fileName = db.Ado.SqlStackTrace.FirstFileName;
                       //代码行数
                       var fileLine = db.Ado.SqlStackTrace.FirstLine;
                       //方法名
                       var FirstMethodName = db.Ado.SqlStackTrace.FirstMethodName;
                   }
               };
           }

           );
    }
}
